#ifndef __CFRUSTUM_H__
#define __CFRUSTUM_H__

#include "StdDefs.h"
#include "CMathFixed.h"
#include "CVector3d.h"
#include "CPlane.h"
#include "CSphere.h"
 



class CFrustum
{
public:
	enum Plane {
		Left = 0,
		Top,
		Right,
		Bottom,
		Near,
		Far
	};

	static const int32 NumberOfPlanes;

public:
	CFrustum();
	CFrustum( const CFrustum& f );
	CFrustum( const CVector3d* pts, fixed farPlaneDistanceFromApex );
	CFrustum( const CVector3d& apex, 
			  const CVector3d& nearLeftTop, const CVector3d& nearRightTop, 
			  const CVector3d& nearRightBottom, const CVector3d& nearLeftBottom,
			  fixed farPlaneDistanceFromApex );
	~CFrustum();

	void				Set( const CVector3d* pts, fixed farPlaneDistanceFromApex );
	void				Set( const CVector3d& apex,
							 const CVector3d& nearLeftTop, const CVector3d& nearRightTop, 
							 const CVector3d& nearRightBottom, const CVector3d& nearLeftBottom,
							 fixed farPlaneDistanceFromApex );
	
	CSpace::Relativity	DetermineSpace( const CSphere& s ) const;

	CPlane&				GetPlane( Plane name );
	const CPlane&		GetPlane( Plane name ) const;

	CFrustum&			operator=( const CFrustum& other );

protected:
	CPlane*				m_plane;
};

 


inline
CFrustum::~CFrustum()
{
	if( m_plane ) 
	{
		delete[] m_plane;
		m_plane = NULL;
	}
}


inline
void CFrustum::Set( const CVector3d* pts, fixed farPlaneDistanceFromApex )
{
	Set( pts[0], pts[1], pts[2], pts[3], pts[4], farPlaneDistanceFromApex );
}
 

inline
CPlane& CFrustum::GetPlane( Plane name )
{
	ASSERT( name < NumberOfPlanes );

	return m_plane[ name ]; 
}


inline
const CPlane& CFrustum::GetPlane( Plane name ) const
{
	ASSERT( name < NumberOfPlanes );

	return m_plane[ name ]; 
}


#endif // __CFRUSTUM_H__